package com.example.demo.security;//package com.example.demo1.security;
//import com.example.demo1.mapper.UserMapper;
//import com.example.demo1.service.UserService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.Customizer;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.security.provisioning.InMemoryUserDetailsManager;
//import org.springframework.security.web.SecurityFilterChain;
//
//@Configuration
//@EnableWebSecurity
//public class SecurityConfig{
//    @Autowired
//    private UserService userService;
//    @Bean
//    UserDetailsService userDetailsService(){
//        InMemoryUserDetailsManager users = new InMemoryUserDetailsManager();
//        users.createUser(User.withUsername("123").password("234").roles("user").build());
//        return users;
//    }
//    @Bean
//    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception{
//
////        httpSecurity.csrf(csrf->csrf.disable())
////                .authorizeHttpRequests((authz)->
////                        authz
////                                .requestMatchers("/user").permitAll()
////                );
//        http.authorizeHttpRequests((auth)->{
//            auth
//                    .requestMatchers("/user").hasRole("user")
//                    .anyRequest()
//                    .authenticated();
//        });
//        http.formLogin((formLogin)->{
////            .loginPage("/login")//这是拦截后去往的地方，登陆页面
//                    formLogin
//                    .loginProcessingUrl("/login")//这是登陆接口
//                    .defaultSuccessUrl("/hello.html");//登陆成功后进入的页面
//        });
//        http.csrf(Customizer.withDefaults());//这是一个跨域漏洞防御，需要关闭
//        http.logout((logoutConfigurer)->{
//            logoutConfigurer.invalidateHttpSession(true);
//        });
//        return http.build();
////        return httpSecurity.build();
//    }
//
//
//}

//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//
//@Configuration
//public class SecurityConfig{
//    @Bean
//    public PasswordEncoder passwordEncoder (){
//        return new BCryptPasswordEncoder();
//    }
//}
